using System.Collections.Generic;
using UnityEngine;

public class CareerListButton : MonoBehaviour
{
	public UISprite flag;

	public UILabel nameLabel;

	public UILabel subtitleLabel;

	public List<UISprite> stars = new List<UISprite>();

	public Color notActiveStarColor;

	public Color activeStarColor = Color.white;

	public Color notActiveColor;

	public CareerSettings.CareerOpponent opponent { get; protected set; }

	public void Init(CareerSettings.CareerOpponent opponent)
	{
		this.opponent = opponent;
		GameConstants.SetFlag(flag, (int)opponent.flag);
		nameLabel.text = opponent.name;
		SetActiveStars(opponent.starCount);
		base.gameObject.SetActive(true);
		GetComponent<UIWidget>().color = ((!opponent.isActive) ? notActiveColor : Color.white);
		if (opponent.starCount == 1)
		{
			subtitleLabel.text = "Win with " + opponent.scoreDiffFor2Stars + " lead for 2 stars!";
		}
		else if (opponent.starCount == 2)
		{
			subtitleLabel.text = "Win with " + opponent.scoreDiffFor3Stars + " load for 2 stars!";
		}
		else
		{
			subtitleLabel.cachedGameObject.SetActive(false);
		}
	}

	public void SetActiveStars(int activeStarCount)
	{
		for (int i = 0; i < stars.Count; i++)
		{
			stars[i].color = ((i >= activeStarCount) ? notActiveStarColor : activeStarColor);
		}
	}

	public void OnClick()
	{
		if (opponent.isActive)
		{
			BehaviourSingleton<ScreenNavigation>.instance.LoadMatch(opponent.ToMatchParameters());
		}
		else
		{
			UIDialog.instance.ShowOk("Level not opened", "Win against previous opponents to open this one!", "Ok", null);
		}
	}
}
